<?php
/**
 * @fileoverview    封装关注模块--添加关注~取消关注
 * @author          gaojian3
 * @date            2012-03-22
 * @copyright       sina meila
 * @param           $uid
 * @param             $vuid?
 * @return             
 */


class ml_biz_follow {
    private $oFollow;
    private $oFans;
    private $_visitor;
    private $oRedis;
    public  $_result;
    private $_uid;
    
    public function __construct($vuid){
        $this->oFollow = new ml_model_dbFollow();
        $this->oFans = new ml_model_dbFans();
        $this->oRedis = new ml_model_rdsCount();
        $this->_vuid = $vuid;
        
    }
  
    public function addFollow($uid){
        $this->_uid = $uid;
        
        $rs1=$this->isFollow($isFollow);
        if(!$rs1 || $isFollow)
            return $this->_result;
            
        $rs2=$this->isOverCnt();
        if($rs2)
            return $this->_result;
        
        $rs3 = $this->oFollow->addFollow($this->_vuid, $this->_uid);
        if(!$rs3) {
            $this->_result['code']=ML_RCODE_BUSY;
            $this->_result['msg']='add follow fail';
            return $this->_result;
        }
        
        $rs4 = $this->oFans->addFans( $this->_uid ,$this->_vuid);
        if(!$rs4) {
            $this->_result['code']=ML_RCODE_BUSY;
            $this->_result['msg']='add fans fail';
            return $this->_result;
        }
            
        $this->oRedis->incrFollowCnt($this->_vuid); 
        $this->oRedis->incrFansCnt($this->_uid);
        $this->addFollowNotice();

        $this->_result['code']=ML_RCODE_SUCC;
        return $this->_result;
    }
    
    public function cancelFollow($uid){
        $this->_uid = $uid;
        
        
    }
    
    public function isFollow(&$isFollow){
        $rs = $this->oFollow->isFollow($this->_vuid,$this->_uid);
        if(!$rs){
            $this->_result['code']=ML_RCODE_BUSY;
            return false;
        }
        $isFollow = $this->oFollow->get_data();
        if($isFollow){
            $this->_result['code']=ML_RCODE_BUSY;
            $this->_result['msg']='followed yet';
        }
        return true;
    }
    
    public function isOverCnt(){
        $followCnt = $this->oRedis->getFollowCnt($this->_vuid);
        
        if($followCnt >= ML_FOLLOW_MAXNUM) {
            $this->_result['code']=ML_RCODE_FAIL;
            $this->_result['msg']='beyond';
            return true;
        }else{
            return false;
        }
    }
    
    public function addFollowNotice(){
        $oRdsNotice=new ml_model_rdsNotice();
        $oRdsNotice->add_notice($this->_uid, ml_model_rdsNotice::NTCTYPE_ADDFANS);
    }
}